﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using Citrix.Cmp;
using System.Windows;

namespace Citrix.XaAdminMobile.ViewModel
{
    /// <summary>
    /// Used to display an error popup when we cannot get a successful response from a XenApp
    /// server.
    /// </summary>
    internal class ErrorStatusViewModel : INotifyPropertyChanged
    {
        /// <summary>
        /// The error message.
        /// </summary>
        private string errorMessage = null;

        /// <summary>
        /// The error message to display to the user. Any non-null/empty message will cause the
        /// popup to be displayed.
        /// </summary>
        public string ErrorMessage
        {
            get
            {
                return this.errorMessage;
            }
            set
            {
                if (!string.Equals(value, this.errorMessage))
                {
                    this.errorMessage = value;
                    OnPropertyChanged("ErrorMessage");
                    OnPropertyChanged("ErrorVisibility");
                }
            }
        }

        /// <summary>
        /// The visibility of the status popup.
        /// </summary>
        public Visibility ErrorVisibility
        {
            get
            {
                if (string.IsNullOrEmpty(this.errorMessage))
                {
                    return Visibility.Collapsed;
                }
                else
                {
                    return Visibility.Visible;
                }
            }
        }

        #region INotifyPropertyChanged Members

        /// <summary>
        /// Fired whenever a public property changes.
        /// </summary>
        public event PropertyChangedEventHandler PropertyChanged;

        /// <summary>
        /// Fires the property change event.
        /// </summary>
        /// <param name="propertyName">The name of the property that changed.</param>
        private void OnPropertyChanged(string propertyName)
        {
            NotifyHelper.VerifyProperty(propertyName, this);
            if (this.PropertyChanged != null)
            {
                this.PropertyChanged.Raise(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        #endregion // INotifyPropertyChanged Members
    }
}